from threading import currentThread, Thread
from time import sleep


def fun_tread(sec, tname):
    # 修改线程名
    print("启动线程->", currentThread().getName(), ":", currentThread().is_alive())

    print("setName修改线程名称")
    currentThread().setName(tname)
    sleep(sec)
    print("{} 线程结束".format(currentThread().getName()))


if __name__ == "__main__":
    threads = []
    for i in range(3):
        t = Thread(target=fun_tread, name="thread-%d" % i, args=(3, "My" + str(i) + "Thread"))
        threads.append(t)
        t.start()
    for t in threads:
        t.join()    # 加入到主线程中,避免主线程过早结束导致子线程被强制终止
    print("-----MainThread线程执行结束了-----")
